package api

import (
	"github.com/gin-gonic/gin"
	"gorm.io/gorm"
)

// SetupRoutes 设置所有API路由
func SetupRoutes(r *gin.Engine, db *gorm.DB) {
	// 创建API处理器
	employeeHandler := NewEmployeeHandler(db)
	shiftHandler := NewShiftHandler(db)
	scheduleHandler := NewScheduleHandler(db)
	productHandler := NewProductHandler(db)

	// API路由组
	api := r.Group("/api")

	// 员工相关路由
	api.GET("/employees", employeeHandler.GetEmployees)
	api.GET("/employees/:id", employeeHandler.GetEmployee)
	api.POST("/employees", employeeHandler.CreateEmployee)
	api.PUT("/employees/:id", employeeHandler.UpdateEmployee)
	api.DELETE("/employees/:id", employeeHandler.DeleteEmployee)

	// 班次相关路由
	api.GET("/shifts", shiftHandler.GetShifts)
	api.GET("/shifts/:id", shiftHandler.GetShift)
	api.POST("/shifts", shiftHandler.CreateShift)
	api.PUT("/shifts/:id", shiftHandler.UpdateShift)
	api.DELETE("/shifts/:id", shiftHandler.DeleteShift)

	// 排班相关路由
	api.GET("/schedules", scheduleHandler.GetSchedules)
	api.GET("/schedules/:id", scheduleHandler.GetSchedule)
	api.POST("/schedules", scheduleHandler.CreateSchedule)
	api.PUT("/schedules/:id", scheduleHandler.UpdateSchedule)
	api.DELETE("/schedules/:id", scheduleHandler.DeleteSchedule)
	api.GET("/schedules/calendar", scheduleHandler.GetSchedulesByDateRange) // 日历视图API

	// 产品相关路由
	api.GET("/products", productHandler.GetProducts)
	api.GET("/products/:id", productHandler.GetProduct)
	api.POST("/products", productHandler.CreateProduct)
	api.PUT("/products/:id", productHandler.UpdateProduct)
	api.DELETE("/products/:id", productHandler.DeleteProduct)
}
